package com.app.web.oauth2

import org.springframework.stereotype.Service
/**
 * Created by three on 14-8-20.
 */
@Service
class OAuthServiceImpl implements OAuthService {
    private static Map<String, String> cache = new HashMap<String, String>();

    @Override
    public void addAuthCode(String authCode, String username) {
        cache.put(authCode, username);
    }

    @Override
    public void addAccessToken(String accessToken, String username) {
        cache.put(accessToken, username);
    }

    @Override
    public String getUsernameByAuthCode(String authCode) {
        return (String)cache.get(authCode);
    }

    @Override
    public String getUsernameByAccessToken(String accessToken) {
        return (String)cache.get(accessToken);
    }

    @Override
    public boolean checkAuthCode(String authCode) {
        return cache.get(authCode) != null;
    }

    @Override
    public boolean checkAccessToken(String accessToken) {
        return cache.get(accessToken) != null;
    }

    @Override
    public boolean checkClientId(String clientId) {
        return true;
    }

    @Override
    public boolean checkClientSecret(String clientSecret) {
        return true;
    }

    @Override
    public long getExpireIn() {
        return 3600L;
    }
}
